// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data
{
    /// <summary>
    ///     A static factory class for creating ISqlBuilder objects.
    /// </summary>
    public static class SqlBuilderFactory
    {
        private static readonly ISqlBuilderFactory _factory = new SqlBuilderFactoryBase();

        static SqlBuilderFactory()
        {
            Cache = new SqlBuilderCache();
        }

        /// <summary>
        ///     Creates an TSqlBuilder type object, TSqlBuilder is the derived interface of ISqlBuilder.
        /// </summary>
        /// <typeparam name="TSqlBuilder">
        ///     The type of interface which is inherited from the ISqlBuilder interface. 
        ///     Such as ISqlQueryBuilder, ISqlInsertBuilder, ISqlDeleteBuilder, ISqlUpdateBuilder, and ISqlRawBuilder.
        /// </typeparam>
        /// <param name="name">The name of the newly created ISqlBuilder object.</param>
        /// <returns>Returns the newly created TSqlBuilder object.</returns>
        public static TSqlBuilder Create<TSqlBuilder>(string name = "")
            where TSqlBuilder : ISqlBuilder
        {
            return _factory.Create<TSqlBuilder>(name);
        }

        /// <summary>
        ///     Gets an ISqlBuilderCache object that provides caching function for ISqlBuilder objects.
        /// </summary>
        public static ISqlBuilderCache Cache { get; }
    }
}
